﻿function get_News_Html(){
  var htmlstr='<table id="Grid_News" style="width:auto;height:auto"></table><div id="addNewsdiv" style="display:none"></div><div id="edtNewsdiv" style="display:none"></div>';
  return htmlstr;
}
function getadd_News_Html(){
  var htmlstr='<div id="AddDlg_News" title="添加记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻分类名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NewTypeName" id="add_NewTypeName" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Title" id="add_Title" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_ContentText" id="add_ContentText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NewKey" id="add_NewKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否首页热门 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_IsHomeHot" id="add_IsHomeHot" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否分类热门 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_IsTypeHot" id="add_IsTypeHot" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 发布时间 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_PostTime" id="add_PostTime" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="addbt_News" href="javascript:void(0)" onclick="Add_News()"> 添 加 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function getedt_News_Html(){
  var htmlstr='<div id="EditDlg_News" title="修改记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻标识 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NewId" id="edt_NewId" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻分类名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NewTypeName" id="edt_NewTypeName" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Title" id="edt_Title" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 新闻内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_ContentText" id="edt_ContentText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NewKey" id="edt_NewKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否首页热门 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_IsHomeHot" id="edt_IsHomeHot" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 是否分类热门 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_IsTypeHot" id="edt_IsTypeHot" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 发布时间 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_PostTime" id="edt_PostTime" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="edtbt_News" href="javascript:void(0)" onclick="Edit_News()"> 修 改 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function Add_News_Tab(tabname){
  if(!$('#ttab').tabs('exists',tabname)){
	$('#ttab').tabs('add',{
		title:tabname,
		cache:false,
		closable:true,
		content:get_News_Html()
	  });
	var gridht = $('body').layout('panel','center').panel('options').height - 58;
	$('#Grid_News').datagrid({
	  border:false,
	  nowrap: false,
	  striped: true,
	  collapsible:true,
	  url:'/Data/News.ashx',
	  method:'get',
	  height:gridht,
	  queryParams:{type:"0"},
	  fitColumns:true,
	  loadMsg:'正在读取数据,请稍候...',
	  singleSelect:true,
	  columns:[[
		{field:'NewId',checkbox:true},
		{field:'NewTypeName',title:'新闻分类名',width:80},
		{field:'Title',title:'新闻标题',width:80},
		{field:'ContentText',title:'新闻内容',width:80},
		{field:'NewKey',title:'关键字',width:80},
		{field:'IsHomeHot',title:'是否首页热门',width:80},
		{field:'IsTypeHot',title:'是否分类热门',width:80},
		{field:'PostTime',title:'发布时间',width:80}]],
	  pagination:true,
	  rownumbers:true,
	  toolbar:[{
		id:'btn_News_add',
		text:'添加',
		iconCls:'icon-add',
		handler:function(){
		  ShowNewsAddFrom();}
		},'-',{
		id:'btn_News_edit',
		text:'修改',
		iconCls:'icon-edit',
		handler:function(){
		  GetOne_News();}
		},'-',{
		id:'btn_News_del',
		text:'删除',
		iconCls:'icon-remove',
		handler:function(){
		 Del_News();}
	  }],
	  onLoadError:function(er){
		  $.messager.alert('错误','可能无查看权限,无法加载数据!','error');
	  }
	});
  }else{
	$('#ttab').tabs('select',tabname);
  }
}
function ShowNewsAddFrom(){
  $('#addNewsdiv').html(getadd_News_Html());
  $('#AddDlg_News').window({
	  title: '添加',
	  width: 600,
	  modal: true,
	  shadow: true,
	  closed: true,
	  height: 400
  });
  $('#addbt_News').linkbutton({iconCls:"icon-ok"});
  $('#AddDlg_News').window('open');
}
function ShowNewsEdtFrom(){
  $('#edtNewsdiv').html(getedt_News_Html());
}
function Add_News(){
  $.get("/Data/News.ashx",{type:2,NewTypeName:$('#add_NewTypeName').val(),Title:$('#add_Title').val(),ContentText:$('#add_ContentText').val(),NewKey:$('#add_NewKey').val(),IsHomeHot:$('#add_IsHomeHot').val(),IsTypeHot:$('#add_IsTypeHot').val(),PostTime:$('#add_PostTime').val()},
  function(data){
    $('#AddDlg_News').window('close');
	$('#Grid_News').datagrid("reload");
  });
}
function GetOne_News(){
  var getid=0;
  var selected = $('#Grid_News').datagrid('getSelected');
  if (selected){
    getid=selected.NewId;
	$.getJSON("/Data/News.ashx",{type:1,id:getid},
	function(data){
			ShowNewsEdtFrom();
			$('#EditDlg_News').window({
				title: 'Edit News',
				width: 600,
				modal: true,
				shadow: true,
				closed: true,
				height: 300
				});
			$('#EditDlg_News').window('open');
			$('#edtbt_News').linkbutton({iconCls:"icon-ok"});
						$('#edt_NewId').val(data.model.NewId);
						$('#edt_NewTypeName').val(data.model.NewTypeName);
						$('#edt_Title').val(data.model.Title);
						$('#edt_ContentText').val(data.model.ContentText);
						$('#edt_NewKey').val(data.model.NewKey);
						$('#edt_IsHomeHot').val(data.model.IsHomeHot);
						$('#edt_IsTypeHot').val(data.model.IsTypeHot);
						$('#edt_PostTime').val(data.model.PostTime);
			
      });
	}else{
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
	}
}
function Edit_News(){
  $.get("/Data/News.ashx",{type:4,NewId:$('#edt_NewId').val(),NewTypeName:$('#edt_NewTypeName').val(),Title:$('#edt_Title').val(),ContentText:$('#edt_ContentText').val(),NewKey:$('#edt_NewKey').val(),IsHomeHot:$('#edt_IsHomeHot').val(),IsTypeHot:$('#edt_IsTypeHot').val(),PostTime:$('#edt_PostTime').val()},
  function(data){
    $('#EditDlg_News').window('close');
	$('#Grid_News').datagrid("reload");
  }); 
}
function Del_News(){
  var getid=0;
  var selected = $('#Grid_News').datagrid('getSelected');
  if(!selected){
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
			return;
  }
  
  getid=selected.NewId;
  $.messager.confirm('确认删除', '请确认是否进行此操作?', function(r){
	  if(r){
			$.get("/Data/News.ashx",{type:3,id:getid},
			function(data){
				$.messager.show({
					title:'提示',
					msg:'已删除数据.',
					timeout:3000,
					showType:'slide'
				});
				$('#Grid_News').datagrid("reload");
			}); 
		  }
  }); 
} 
  